package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;
//1. 解决这个问题，可以通过随机生成的uuid来实现
//2. 在 `ShowAddPageServlet` 跳转页面前，先生成一个 uuid，将该uuid存储一份到session中，存储一份到request域对象中，然后跳转到add.jsp 页面
//3. add.jsp页面在提交数据时需要连同 uuid一并提交到 `/addGoods` 资源

@WebServlet("/showAddPage")
public class ShowAddPageServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //使用UUID生成随机id
        String ID = UUID.randomUUID().toString();
        System.out.println(ID);
        //将UUID存入Session中
        request.getSession().setAttribute("uuid",ID);
        //跳转到 add.jsp 页面
        request.getRequestDispatcher("/WEB-INF/pages/add.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
